﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace baseClass.controls
{
    public partial class employee_emergency : common.control.baseUserControl  
    {
        private Color saveNormalFC = application.Settings.sysColorNormalFG;
        public employee_emergency()
        {
            InitializeComponent();
            saveNormalFC = contactName1Ed.ForeColor;
            SetMaxLength();
        }

        private void SetMaxLength()
        {
            data.baseDS.employeeDataTable tbl = new data.baseDS.employeeDataTable();
            contactName1Ed.maxlen = tbl.emerContact1Column.MaxLength;
            contactAddr1Ed.maxlen = tbl.emerContactAddr1Column.MaxLength;
            contactPhone1Ed.maxlen = tbl.emerContactPhone1Column.MaxLength;

            contactName2Ed.maxlen = tbl.emerContact2Column.MaxLength;
            contactAddr2Ed.maxlen = tbl.emerContactAddr2Column.MaxLength;
            contactPhone2Ed.maxlen = tbl.emerContactPhone2Column.MaxLength;

            noteEd.MaxLength = tbl.emerNotesColumn.MaxLength;
        }
        public virtual void LoadData(){}

        public virtual void SetData(data.baseDS.employeeRow row)
        {
            contactName1Ed.Text = (row.IsemerContact1Null()?"":row.emerContact1);
            contactAddr1Ed.Text = (row.IsemerContactAddr1Null() ? "" : row.emerContactAddr1);
            contactPhone1Ed.Text = (row.IsemerContactPhone1Null() ? "" : row.emerContactPhone1);

            contactName2Ed.Text = (row.IsemerContact2Null() ? "" : row.emerContact2);
            contactAddr2Ed.Text = (row.IsemerContactAddr2Null() ? "" : row.emerContactAddr2);
            contactPhone2Ed.Text = (row.IsemerContactPhone2Null() ? "" : row.emerContactPhone2);

            noteEd.Text = (row.IsemerNotesNull() ? "" : row.emerNotes);
        }
        public virtual void GetData(data.baseDS.employeeRow row)
        {
            if (contactName1Ed.Text.Trim() == "") row.SetemerContact1Null(); else row.emerContact1 = contactName1Ed.Text.Trim();
            if (contactAddr1Ed.Text.Trim() == "") row.SetemerContactAddr1Null(); else row.emerContactAddr1 = contactAddr1Ed.Text.Trim();
            if (contactPhone1Ed.Text.Trim() == "") row.SetemerContactPhone1Null(); else row.emerContactPhone1 = contactPhone1Ed.Text.Trim();

            if (contactName2Ed.Text.Trim() == "") row.SetemerContact2Null(); else row.emerContact2 = contactName2Ed.Text.Trim();
            if (contactAddr2Ed.Text.Trim() == "") row.SetemerContactAddr2Null(); else row.emerContactAddr2 = contactAddr2Ed.Text.Trim();
            if (contactPhone2Ed.Text.Trim() == "") row.SetemerContactPhone2Null(); else row.emerContactPhone2 = contactPhone2Ed.Text.Trim();

            if (noteEd.Text.Trim() == "") row.SetemerNotesNull(); else row.emerNotes = noteEd.Text.Trim();
        }
        public virtual bool CheckData()
        {
            bool retVal = true;
            contactPhone1Lbl.ForeColor = saveNormalFC;
            contactPhone2Lbl.ForeColor = saveNormalFC;

            if (contactName1Ed.Text.Trim() != "" && contactPhone1Ed.Text.Trim()=="")
            {
                contactPhone1Lbl.ForeColor = application.Settings.sysColorHiLightFG;
                retVal = false;
            }
            
            if (contactName2Ed.Text.Trim() != "" && contactPhone2Ed.Text.Trim() == "")
            {
                contactPhone2Lbl.ForeColor = application.Settings.sysColorHiLightFG;
                retVal = false;
            }
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            contactName1Ed.ReadOnly = state;
            contactAddr1Ed.ReadOnly = state;
            contactPhone1Ed.ReadOnly = state;

            contactName2Ed.ReadOnly = state;
            contactAddr2Ed.ReadOnly = state;
            contactPhone2Ed.ReadOnly = state;

            noteEd.ReadOnly = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            contactName1Ed.Focus();
        }
    }
}
